﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Text.RegularExpressions;
using System.IO;
using Slja.Lib;

namespace Slja.WEB.Design
{
    /// <summary>
    /// FilepackDel 的摘要说明
    /// </summary>
    public class FilepackDel : IHttpHandler
    {
        
       
        public void ProcessRequest(HttpContext context)
        {
            try
            {
                BLL.PrjDesignFilepack bll = new BLL.PrjDesignFilepack();
                string strIds = context.Request.Form["filepackids"];

                string[] arr = strIds.Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries);
                for (int i = 0; i < arr.Length; i++)
                {
                    if (arr[i] == "0" || arr[i] == "") { continue; }
                    //删除文件
                    Model.PrjDesignFilepack model = bll.GetModel(int.Parse(arr[i]));
                    if (model != null)
                    {
                        string physicPath = context.Server.MapPath(model.FilepackPath);
                        File.Delete(physicPath);
                        //删除数据记录
                        bll.Delete(model.ID);
                    }
                }
                 context.Response.Write("({status:'true',msg:'删除成功'})");
            }
            catch (Exception err)
            {
                string errormsg = StringHandle.ClearBR(StringHandle.ReplaceString(err.Message, "'", "|", false)); 

                context.Response.Write("({status:'false',msg:'删除失败"+errormsg+"'})");
            }
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}